/****************************************\
|* MFZPSP LLE PSP Emulator              *|
|* Copyright (c) 2008 Mauro Frischherz  *|
|* See License.txt for details          *|
\****************************************/

#include "log.h"
#include <stdio.h>

FILE* pLogFile;
bool open = false;

void initlog()
{
	pLogFile = fopen(".\\log.txt", "w+");
	if(pLogFile)
		open = true;
}

void endlog()
{
	fclose(pLogFile);
	open = false;
}

void printbool(char* BoolString, int retVal)
{
	printf("ACTION: %s - %s\n", BoolString, (retVal ? "success" : "failure"));
	if(open)
		fprintf(pLogFile, "ACTION: %s - %s\n", BoolString, (retVal ? "success" : "failure"));
}

void printerror(char* ErrorString)
{
	printf("ERROR : %s\n", ErrorString);
	if(open)
		fprintf(pLogFile, "ERROR : %s\n", ErrorString);
}

void printevent(char* EventString)
{
	printf("EVENT : %s\n", EventString);
	if(open)
		fprintf(pLogFile, "EVENT : %s\n", EventString);
}

void printfact(char* String)
{
	printf("%s\n", String);
	if(open)
		fprintf(pLogFile, "%s\n", String);
}

inline void printsyscall(uint Code)
{
	printf("EVENT : SysCall: %x", Code);
	if(open)
		fprintf(pLogFile, "EVENT : SysCall: %x", Code);
}

char getsinglechar()
{
	return getchar();
}

inline void printunknowninst(uint OpCode)
{
	printf("ERROR : Unknown Instruction: %08X\n", OpCode);
	if(open)
		fprintf(pLogFile, "ERROR : Unknown Instruction: %08X\n", OpCode);
}
